package scenic.study;

import org.jdom2.*;
import org.jdom2.input.SAXBuilder;
import org.junit.Test;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.function.Consumer;


/**
 * Created by scenic on 2017/11/9.
 */
public class JDOM {


    @Test
    public void test() throws JDOMException, IOException {

        SAXBuilder sb = new SAXBuilder();
        URL path = getClass().getClassLoader().getResource("test.xml");
        System.out.println(path);
        Document document = sb.build(path);
        Element rootElement = document.getRootElement();
        System.out.println(document);
        List<Element> disks = rootElement.getChildren("disk");
        disks.forEach(element -> {
            String name = element.getAttributeValue("name");
            String capacity = element.getChildText("capacity");
            String directories = element.getChildText("directories");
            System.out.println(name + " " + capacity + "　" +directories);
        });

    }
}
